总是让客户去APPDATA路径下找日志,因为这个路径不需要什么管理员权限,有的人不知道在哪,找半天也找不到。所以写了个日志文件自动提取的小程序。提取完可以配合一些压缩库将文件压缩
#include
#include
#include
#include
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//获得程序运行目录,读取同目录下的配置文件,这里日志是appdata/local和appdata/roaming都有
QString exePath = QCoreApplication::applicationDirPath();
QSettings* pathsettings = new QSettings(exePath.append("/config.ini"), QSettings::IniFormat);
pathsettings->beginGroup("Config");
int localnum = pathsettings->value("Local_Max").toInt();
int roamingnum = pathsettings->value("Roaming_Max").toInt();
pathsettings->endGroup();
//将配置文件中填写的日志都拷贝到程序目录下的Log文件夹
pathsettings->beginGroup("LocalPath");
for (int i = 0; i
exePath = QCoreApplication::applicationDirPath();
QString tmpLocal = QString("log%1").arg(i);
QString tmpLogName = pathsettings->value(tmpLocal).toString();
QStringList tmpList = QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation);
QString tmpStr = tmpList[0];// appdata/local
tmpStr.chop(5);
tmpStr.append("Roaming");
tmpStr.append("/");
tmpStr.append(tmpLogName);
QFile tmpFile(tmpStr);
if (tmpFile.exists())
tmpFile.copy(exePath.append("/Log/%1").arg(tmpLogName));
}
pathsettings->endGroup();
printf("\n\n\n=======日志已全部收集到Log文件夹下======\n\n\n");
system("pause");
//return a.exec();
return 0;
}
|